
<?php 
/*
Template Name: upload_image_jquery - ajax
*/
?>
<?php get_header(); ?>
 
<?php 

  if ( !is_user_logged_in() ) 
    {
      ?>

        <div id='content_nano_two' class='clearfix' style='min-height:300px;'>
              <h1 style='color:#000;'>bạn không được phép truy cập trang này </h1>
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        </div>
         
     <?php 
          
    }//if ( ! current_user_can( 'list_users' ) ) 
    elseif (is_user_logged_in() )  
 { 

    if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      {
       ?>

        <div id='content_nano_two' class='clearfix' style='min-height:300px;'>
              <h1 style='color:#000;'>bạn không được phép truy cập trang này </h1>
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        </div>
         
     <?php 

      }//if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
      {
     ?>

<div id="content_nano_three" class="clearfix">
    
     <div id="breaum_suausser"><h2>Thêm Máy</h2></div>

		<div id="content" class='edit_user-page_phuc'>

		<div class="wrap">
					<div><br></div><h2 id="add-new-user"> Thêm </h2>
					<p>Tạo máy mới và thêm vào trang này</p>
					<form action="<?php bloginfo('url');?>/process-product" method="POST"  id="creatproduct">
						<input name="id_may" type="hidden" id='id_may' value="createuser">
						<table class="form-table">
							<tbody>
								<tr class="form-field form-required">
								<th scope="row">
									<label Style='font-size:20px;font-weight:bold;'>Tên Máy<span class="description"></span>
									</label>
								</th>
								<td>
									<input name="name_may" type="text" id="name_may" value="" aria-required="true">
								</td>
							</tr>
							<tr class="form-field form-required">
								<?php //print_r($_FILES);?>

								<div class="container">
   
    

							    <!-- The fileinput-button span is used to style the file input field as button -->
							    <span class="btn btn-success fileinput-button">
							        <i class="glyphicon glyphicon-plus"></i>
							        <span>Add files...</span>
							        <!-- The file input field used as target for the file upload widget -->
							        <input id="fileupload" type="file" name="files[]" multiple>
							    </span>
							    <br>
							    <br>
							    <!-- The global progress bar -->
							    <div id="progress" class="progress">
							        <div class="progress-bar progress-bar-success"></div>
							    </div>
							    <!-- The container for the uploaded files -->
							    <div id="files" class="files"></div>
							</div>

							 
							</tr>
							<!-- 
							<tr class="form-field">
								<th scope="row"><label for="ngay_tao"></label></th>
								<td><input name="ngay_tao" type="hidden" id="ngay_tao" value=""></td>
							</tr>
							<tr class="form-field">
								<th scope="row"><label for="ngay_sua"></label></th>
								<td><input name="ngay_sua" type="hidden" id="ngay_sua" value=""></td>
							</tr>
							-->
							</tbody>
						</table>

						<p class="submit">
							<input type="submit" name="create_may" id="create_may" class="button button-primary" value="Thêm Máy Mới "> 
						</p>
					 </form>
		</div><!-- end class="wrap" --> 
       </div><!--- id="content" -->
</div><!-- id="content_nano_three" -->

<?php 
} //  elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
} //elseif ( ! current_user_can( 'list_users' ) )  
 ?>

                        <script>
								/*jslint unparam: true, regexp: true */
								/*global window, $ */
								jQuery(function () {
								    'use strict';
								    // Change this to the location of your server-side upload handler:
								    var url = window.location.hostname === 'blueimp.github.io' ?
								                '//jquery-file-upload.appspot.com/' : 'server/php/',
								        uploadButton = $('<button/>')
								            .addClass('btn btn-primary')
								            .prop('disabled', true)
								            .text('Processing...')
								            .on('click', function () {
								                var $this = $(this),
								                    data = $this.data();
								                $this
								                    .off('click')
								                    .text('Abort')
								                    .on('click', function () {
								                        $this.remove();
								                        data.abort();
								                    });
								                data.submit().always(function () {
								                    $this.remove();
								                });
								            });
								    jQuery('#fileupload').fileupload({
								        url: url,
								        dataType: 'json',
								        autoUpload: false,
								        acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
								        maxFileSize: 5000000, // 5 MB
								        // Enable image resizing, except for Android and Opera,
								        // which actually support image resizing, but fail to
								        // send Blob objects via XHR requests:
								        disableImageResize: /Android(?!.*Chrome)|Opera/
								            .test(window.navigator.userAgent),
								        previewMaxWidth: 100,
								        previewMaxHeight: 100,
								        previewCrop: true
								    }).on('fileuploadadd', function (e, data) {
								        data.context = $('<div/>').appendTo('#files');
								        jQuery.each(data.files, function (index, file) {
								            var node = $('<p/>')
								                    .append($('<span/>').text(file.name));
								            if (!index) {
								                node
								                    .append('<br>')
								                    .append(uploadButton.clone(true).data(data));
								            }
								            node.appendTo(data.context);
								        });
								    }).on('fileuploadprocessalways', function (e, data) {
								        var index = data.index,
								            file = data.files[index],
								            node = $(data.context.children()[index]);
								        if (file.preview) {
								            node
								                .prepend('<br>')
								                .prepend(file.preview);
								        }
								        if (file.error) {
								            node
								                .append('<br>')
								                .append($('<span class="text-danger"/>').text(file.error));
								        }
								        if (index + 1 === data.files.length) {
								            data.context.find('button')
								                .text('Upload')
								                .prop('disabled', !!data.files.error);
								        }
								    }).on('fileuploadprogressall', function (e, data) {
								        var progress = parseInt(data.loaded / data.total * 100, 10);
								        jQuery('#progress .progress-bar').css(
								            'width',
								            progress + '%'
								        );
								    }).on('fileuploaddone', function (e, data) {
								        jQuery.each(data.result.files, function (index, file) {
								            if (file.url) {
								                var link = $('<a>')
								                    .attr('target', '_blank')
								                    .prop('href', file.url);
								                $(data.context.children()[index])
								                    .wrap(link);
								            } else if (file.error) {
								                var error = $('<span class="text-danger"/>').text(file.error);
								                $(data.context.children()[index])
								                    .append('<br>')
								                    .append(error);
								            }
								        });
								    }).on('fileuploadfail', function (e, data) {
								        jQuery.each(data.files, function (index, file) {
								            var error = $('<span class="text-danger"/>').text('File upload failed.');
								            $(data.context.children()[index])
								                .append('<br>')
								                .append(error);
								        });
								    }).prop('disabled', !$.support.fileInput)
								        .parent().addClass($.support.fileInput ? undefined : 'disabled');
								});
								</script>
		
<?php get_footer(); ?>